﻿package frEngine.loaders.away3dMd5
{
    import __AS3__.vec.*;
    import flash.geom.*;
    import flash.utils.*;
    import frEngine.*;
    import frEngine.core.*;
    import frEngine.event.*;
    import frEngine.math.*;

    public class SkeletonClipNode extends AnimationClipNodeBase
    {
        public var hasLoaded:Boolean = false;
        public var isInHead:Boolean = true;
        public var frames:Vector.<SkeletonPose>;
        public var skipFrame:int;
        private var _frameLen:int = 0;
        private var surfaceCache:Dictionary;
        private var cacheAllFrameJoints:Dictionary;
        private var _hierarchy:Vector.<HierarchyData>;
        private static var _localOr:Quaternion = new Quaternion();
        private static var _localTr:Vector3D = new Vector3D();

        public function SkeletonClipNode(param1:Number, param2:Number, param3:String, param4:Vector.<HierarchyData>, param5:uint, param6:uint, param7:Boolean, param8:int)
        {
            this.frames = new Vector.<SkeletonPose>;
            this.surfaceCache = new Dictionary(false);
            this.cacheAllFrameJoints = new Dictionary(false);
            super(param1, param2, param3, param5, param6);
            this._hierarchy = param4;
            this.isInHead = param7;
            this.skipFrame = param8;
            this.hasLoaded = this.isInHead;
            return;
        }// end function

        public function setLoaded() : void
        {
            if (this._frameLen == 0)
            {
                this.hasLoaded = false;
            }
            else
            {
                this.hasLoaded = true;
                FrEventDispatcher.instance.proxyDispatchEvent(this, Engine3dEventName.TRACK_LOADED);
            }
            return;
        }// end function

        public function addFrame(param1:SkeletonPose) : void
        {
            this.frames.push(param1);
            _stitchDirty = true;
            this._frameLen = this.frames.length;
            return;
        }// end function

        private function calculateAllFrameBonePose(param1:int) : Vector.<Matrix3D>
        {
            var _loc_2:SkeletonPose = null;
            var _loc_3:JMatrix3D = null;
            var _loc_6:Matrix3D = null;
            var _loc_4:* = new Vector.<Matrix3D>;
            var _loc_5:int = 1;
            while (_loc_5 < this._frameLen)
            {
                
                _loc_2 = this.frames[_loc_5];
                _loc_6 = new Matrix3D();
                _loc_2.jointPoseFromIndex(param1, _loc_6, null);
                _loc_4.push(_loc_6);
                _loc_5++;
            }
            return _loc_4;
        }// end function

        public function getBoneSwordLightSurface(param1:int, param2:int, param3:int, param4:int, param5:Vector3D) : SwordLightSurface
        {
            var _loc_6:* = this.cacheAllFrameJoints[param1];
            if (!_loc_6)
            {
                var _loc_9:* = this.calculateAllFrameBonePose(param1);
                this.cacheAllFrameJoints[param1] = this.calculateAllFrameBonePose(param1);
                _loc_6 = _loc_9;
            }
            var _loc_7:* = "id:" + param1 + ",n:" + param2 + ",y:" + param3 + "sp:" + param4 + "rot:" + param5.toString();
            var _loc_8:* = this.surfaceCache[_loc_7];
            if (_loc_8)
            {
                return _loc_8;
            }
            var _loc_9:* = new SwordLightSurface(_loc_7, _loc_6, param2, param3, param4, param5);
            _loc_8 = new SwordLightSurface(_loc_7, _loc_6, param2, param3, param4, param5);
            this.surfaceCache[_loc_7] = _loc_9;
            return _loc_8;
        }// end function

        public function getGloblePoses(param1:int) : SkeletonPose
        {
            if (param1 > (this._frameLen - 1))
            {
                param1 = this._frameLen - 1;
            }
            if (this._frameLen == 0)
            {
                return null;
            }
            return this.frames[param1];
        }// end function

        public function dispose() : void
        {
            var _loc_2:FrSurface3D = null;
            var _loc_3:SkeletonPose = null;
            var _loc_1:int = 0;
            while (_loc_1 < this._frameLen)
            {
                
                _loc_3 = this.frames[_loc_1];
                _loc_3.dispose();
                _loc_1++;
            }
            for each (_loc_2 in this.surfaceCache)
            {
                
                _loc_2.disposeImp();
            }
            this.frames.length = 0;
            this._frameLen = 0;
            this.surfaceCache = null;
            this.cacheAllFrameJoints = null;
            this._hierarchy = null;
            this.hasLoaded = false;
            this.isInHead = true;
            return;
        }// end function

        override protected function updateStitch() : void
        {
            super.updateStitch();
            return;
        }// end function

    }
}
